﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Model;
using FubiManger.Controls;
namespace FubiManger.UI
{
    partial class ActivitysForm : Smobiler.Core.Controls.MobileForm
    {
        public ActivitysForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 活动集合
        /// </summary>
        List<ms_merchant_activity> actlist = new List<ms_merchant_activity>();
        private string activity_type = "1";
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ActivitysForm_Load(object sender, EventArgs e)
        {
            //merchantid = "2";
            actlist = merchant_activityDal.Querybymerchantid(merchantid, "1");
            Getactivity();
        }
        /// <summary>
        /// 提取活动
        /// </summary>
        private void Getactivity()
        {
            panactivitys.Height = actlist.Count * 140;
            for (int i = 0; i < actlist.Count; i++)
            {
                activityscontrol con = new activityscontrol();
                con.goods_name = actlist[i].goods_name;//商品名称
                con.discount_price = actlist[i].discount_price;//活动价格
                con.market_price = actlist[i].market_price; //市场价
                con.reason = actlist[i].reason;//审核失败原因
                con.activityid = actlist[i].id;//活动编号
                con.audit_status = actlist[i].audit_status;//审核状态
                con.start_time = actlist[i].start_time;//活动开始时间
                con.cover = actlist[i].cover;//封面
                con.end_time = actlist[i].end_time;//结束时间
                con.activity_type = actlist[i].activity_type;//活动类型
                panactivitys.Controls.Add(con);
            }
        }
        /// <summary>
        /// 秒杀活动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnkill_Press(object sender, EventArgs e)
        {
            btnkill.ForeColor = System.Drawing.Color.Black;
            btngroup.ForeColor = System.Drawing.Color.DimGray;
            lbl_kill.Visible = true;
            lbl_group.Visible = false;
            if (panactivitys.Controls.Count > 0)
                panactivitys.Controls.Clear();
            actlist = merchant_activityDal.Querybymerchantid(merchantid, "1");
            Getactivity();
            activity_type = "1";
        }
        /// <summary>
        /// 拼团活动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btngroup_Press(object sender, EventArgs e)
        {
            btngroup.ForeColor = System.Drawing.Color.Black;
            btnkill.ForeColor = System.Drawing.Color.DimGray;
            lbl_kill.Visible = false;
            lbl_group.Visible = true;
            if (panactivitys.Controls.Count > 0)
                panactivitys.Controls.Clear();
            actlist = merchant_activityDal.Querybymerchantid(merchantid, "2");
            Getactivity();
            activity_type = "2";
        }

        private void panadd_Press(object sender, EventArgs e)
        {
            chooseactivitycontrol con = new chooseactivitycontrol();
            con.merchantid = merchantid;
            this.Form.ShowDialog(con, (obj, args) =>
            {
                Refsh();//刷新
            });
        }
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refsh()
        {
            if (activity_type == "1")
            {
                if (panactivitys.Controls.Count > 0)
                    panactivitys.Controls.Clear();
                actlist = merchant_activityDal.Querybymerchantid(merchantid, "1");
                Getactivity();
            }
            else
            {
                if (panactivitys.Controls.Count > 0)
                    panactivitys.Controls.Clear();
                actlist = merchant_activityDal.Querybymerchantid(merchantid, "2");
                Getactivity();
            }
        }
    }
}